// 把路径转换成驼峰命名
import {findMenu} from "@/utils/tabs";

export const pathToCamel = (path: string): string => {
    let backName = path.replace(/\/(\w)/g, (all, letter) => letter.toUpperCase());
    return backName;
}

// 获取svg图标(id)列表
export const getIconList = (): string[] => {
    const rs: string[] = []
    const list = document.querySelectorAll('svg symbol')
    for (let i = 0; i < list.length; i++) {
        rs.push(list[i].id)
    }
    return rs
}

/**
 * 返回url的参数
 * @param name
 */
export const getUrlParam = (name: string): string => {
    let url = window.location.href;
    let getqyinfo = url.split('?')[1]
    if (!getqyinfo) {
        return "";
    }
    let getqys = getqyinfo.split('&')
    for (let i = 0; i < getqys.length; i++) {
        let item = getqys[i].split('=')
        let key = item[0]
        let value = item[1]
        if (key == name) {
            return value;
        }
    }
    return ""
}

export const getUrlParamFromUrl = (url: string, name: string): string => {
    if (!url) {
        return "";
    }
    let getqyinfo = url.split('?')[1]
    if (!getqyinfo) {
        return "";
    }
    let getqys = getqyinfo.split('&')
    for (let i = 0; i < getqys.length; i++) {
        let item = getqys[i].split('=')
        let key = item[0]
        let value = item[1]
        if (key == name) {
            return value;
        }
    }
    return ""
}

export const isNotEmpty = (var1: string): boolean => {
    if (var1 != null && var1 != undefined && var1 != "") {
        return true
    } else {
        return false;
    }
}


export const getTreeIconColor = (node: any) => {
    if (node.level == 1) {
        return "#409EFF";
    } else if (node.level == 2) {
        return "#67C23A";
    } else if (node.level == 3) {
        return "#E6A23C";
    } else if (node.level == 4) {
        return "#F56C6C";
    }
    return "black";
}


export const getRoutePath = (route: any) => {
    let path = route.fullPath || route.path;
    return path;
}
